home *** CD-ROM | disk | FTP | other *** search
/ Acorn User: China / Acorn User China CD-ROM (UK) (Disc A) / Acorn User China CD-ROM (UK) (Disc A).bin / DEMON / DEVELOPER / HYPERMAIL.ARC / !hypermail_c_file < prev    next >
Encoding:
Text File  |  1996-01-24  |  4.5 KB  |  155 lines

  1. /*
  2. ** Copyright (C) 1994, Enterprise Integration Technologies Corp.        
  3. ** All Rights Reserved.
  4. ** Kevin Hughes, kevinh@eit.com 
  5. ** 7/25/94
  6. */
  7.  
  8. #include "hypermail.h"
  9. #include "file.h"
  10.  
  11. #ifdef RISCOS
  12.   #include <stdlib.h>
  13.   #include "OS:osfile.h"
  14. #endif
  15.  
  16. /* Is a file a directory?
  17. */
  18. int isdirectory(path)
  19.      char *path;
  20. {
  21. #ifdef RISCOS
  22. /* Do nothing ...*/
  23. #else
  24.       struct stat stbuf;
  25.  
  26.         if (stat(path, &stbuf))
  27.                 return 0;
  28.         return ((stbuf.st_mode & S_IFMT) == S_IFDIR) ? 1 : 0;
  29. #endif
  30. }
  31.  
  32. /* Does a file exist?
  33. */
  34.  
  35. int isfile(path)
  36.      char *path;
  37. {
  38. #ifdef RISCOS
  39.  
  40. return osfile_read_stamped_path(path,0,0,0,0,0,0);
  41.  
  42. #else
  43.  
  44.         struct stat stbuf;
  45.  
  46.         if (stat(path, &stbuf))
  47.                 return 0;
  48.         return ((stbuf.st_mode & S_IFMT) == S_IFREG) ? 1 : 0;
  49.  
  50. #endif
  51. }
  52.  
  53. /* This tries to create and chmod a directory.
  54. */
  55.  
  56. void checkdir(dir)
  57.      char *dir;
  58. {
  59.         if (!isdirectory(dir)) {
  60. #ifdef RISCOS
  61. /* Do nothing ... */
  62. #else
  63.                 if (mkdir(dir, dirmode) == -1) {
  64.                  
  65.                       sprintf(errmsg,
  66.                         "Couldn't create archive directory \"%s\".", dir);
  67.                         progerr(NULL);
  68.                  }
  69.                 else if (showprogress)
  70.                         printf("Creating directory \"%s\", mode %o.\n",
  71.                         dir, dirmode);
  72.                 if (chmod(dir, dirmode) == -1) {
  73.                         sprintf(errmsg, "Couldn't chmod \"%s\" to %o.",
  74.                         dir, dirmode);
  75.                         progerr(NULL);
  76.                 }
  77. #endif
  78.         }
  79. }
  80.  
  81. /* Reads a configuration file if it exists and puts all the right
  82. ** values into the right variables.
  83. */
  84.  
  85. void readconfigs(path, mbox, label, dir, archives, about, overwrite, increment,
  86. defaultindex)
  87.      char *path;
  88.      char *mbox;
  89.      char *label;
  90.      char *dir;
  91.      char *archives;
  92.      char *about;
  93.      int *overwrite;
  94.      int *increment;
  95.      char *defaultindex;
  96. {
  97.         char tmppath[MAXFILELEN], line[MAXLINE], value[MAXLINE];
  98.         struct passwd *pp;
  99.         FILE *fp;
  100.  
  101.         if (!strcmp(path, "NONE"))
  102.                 return;
  103.         if (path[0] == '~') {
  104. #ifdef RISCOS
  105. /* Probably unnecessary under RISCOS ...*/
  106. #else
  107.                 pp = getpwuid(getuid());
  108.                 sprintf(tmppath, "%s%s", pp->pw_dir, path + 1);
  109. #endif
  110.                 if ((fp = fopen(tmppath, "r")) == NULL)
  111.                         return;
  112.         }
  113.         else {
  114.                 if ((fp = fopen(path, "r")) == NULL)
  115.                         return;
  116.                 printf("path: %s\n", path);
  117.         }
  118.         while (fgets(line, MAXLINE, fp) != NULL) {
  119.                 if (line[0] == '#' || line[0] == '\n')
  120.                         continue;
  121.                 if (getconfvalue(line, "hm_mbox", value) != NULL)
  122.                         strcpy(mbox, value);
  123.                 if (getconfvalue(line, "hm_label", value) != NULL)
  124.                         strcpy(label, value);
  125.                 if (getconfvalue(line, "hm_archives", value) != NULL)
  126.                         strcpy(archives, value);
  127.                 if (getconfvalue(line, "hm_about", value) != NULL)
  128.                         strcpy(about, value);
  129.                 if (getconfvalue(line, "hm_dir", value) != NULL)
  130.                         strcpy(dir, value);
  131.               if (getconfvalue(line, "hm_defaultindex", value) != NULL)
  132.                         strcpy(defaultindex, value);
  133.  
  134.                 if (getconfvalue(line, "hm_progress", value) != NULL)
  135.                         showprogress = atoi(value);
  136.                 if (getconfvalue(line, "hm_overwrite", value) != NULL)
  137.                         *overwrite = atoi(value);
  138.                 if (getconfvalue(line, "hm_increment", value) != NULL)
  139.                         *increment = atoi(value);
  140.                 if (getconfvalue(line, "hm_reverse", value) != NULL)
  141.                         reverse = atoi(value);
  142.                 if (getconfvalue(line, "hm_showheaders", value) != NULL)
  143.                         showheaders = atoi(value);
  144.                 if (getconfvalue(line, "hm_showhtml", value) != NULL)
  145.                         showhtml = atoi(value);
  146.                 if (getconfvalue(line, "hm_thrdlevels", value) != NULL)
  147.                         thrdlevels = atoi(value);
  148.                 if (getconfvalue(line, "hm_dirmode", value) != NULL)
  149.                         dirmode = strtol(value, (char **) NULL, 0);
  150.                 if (getconfvalue(line, "hm_filemode", value) != NULL)
  151.                         filemode = strtol(value, (char **) NULL, 0);
  152.         }
  153.         fclose(fp);
  154. }
  155.